package com.garen.utils;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.StringUtil;

import com.garen.common.AbstractFilter;

//map构造函数
public final class MapBuilder {

	private Map<String,Object> map = new HashMap<String,Object>();
	
	public MapBuilder put(String key,Object obj)
	{
		map.put(key, obj);
		return this;
	}
	
	public Map<String,Object> build()
	{
		/*HttpServletRequest request = AbstractFilter.getRequest();
		if(request != null)
			map.put("ip", AbstractFilter.getRequest().getRemoteAddr());
		else 
			map.put("ip", "127.0.0.2");*/
		return map; 
	}
	//根据key拷贝map
	public static void copyMap(Map<String,Object> source,Map<String,Object> dest,String keys){
		if(source == null || dest == null 
				|| StringUtils.isEmpty(keys)) return;
		for(String key : keys.split(",")){
			dest.put(key, source.get(key));
		}
	}
}
